import utils from "../../utils/index";
import {
  fansModel,commonModel
} from "../../apis/index"
const app = getApp()
import regeneratorRuntime from '../../libs/wxPromise.min';
Page({
  data: {
    placeholder:'输入名星名字',
    name:'', //粉丝团名称
    avatar:'', //粉丝团头像
    sid:'', // 所属明星的ID
  },
  mixins: [require('../../myMixin.js')],
  onLoad: function (options) {

  },
  onShow: function () {
    let item = app.globalData.search_data
    if(item){
      this.setData({
        item:item,
        sid:item.id
      })
    }
  },
  onHide(){
    app.globalData.search_data = ''
  },
  fansClubCreate(){
    let { name, avatar, sid } = this.data
    if(name&&avatar&&sid){
      utils.showLoading()
      fansModel.fansClubCreate({name,avatar,sid}).then(res=>{
        utils.showModalContent('','粉丝团创建成功！', '确定',  false,'').then(res=>{
          if(res){
            utils.navigateBack({
              delta:1
            })
            app.globalData.search_data = ''
          }
          utils.hideAll()
        })
      })
    }else{
      utils.showToast('请添加粉丝团信息','none')
    }
  },
  onInputChange(e){
    let {value} = e.detail
    this.data.name = value.trim()
  },
  onFocus(){
    utils.goUrl(`../search/search?text=选TA&type=2`)
  },
  updateSearchData(item){
    this.setData({
      item:item,
      sid:item.id
    })
  },
  clearItem(){
    this.setData({
      item:{},
      sid:''
    })
  },
  
  chooseImage(){
    let _this= this
    utils.chooseImage({
      count: 1,
      sizeType: ['compressed'],
      sourceType: ['album','camera'],
      success: (result)=>{
        let filePath = result.tempFilePaths[0]
        commonModel.uploadFile({filePath}).then(res=>{
          _this.setData({
            avatar:res
          })
        })
      }
    })
  }
})